package com.lagou.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileInput {

    public static void main(String[] args) throws IOException {
        File file = new File("file.txt");
        // 创建输入流
        FileInputStream fileInputStream = new FileInputStream(file);
        // 获取通道
        FileChannel channel = fileInputStream.getChannel();
        // 分配buffer
        ByteBuffer allocate = ByteBuffer.allocate((int) file.length());
        channel.read(allocate);
        allocate.flip();
        System.out.println(new String(allocate.array()) );

    }
}
